﻿using System.Net;

namespace Test.ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("hello world!");
            string url = "http://img2020.cnblogs.com/blog/2124548/202008/2124548-20200817164613965-493044967.png";
            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.KeepAlive= false;
            httpWebRequest.Referer = "";
            //httpWebRequest.Host = "baike.baidu.com";
            httpWebRequest.UserAgent = "";
            httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
            httpWebRequest.Timeout = 30 * 1000;
            httpWebRequest.Method = "GET";

            HttpWebResponse webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            if(webResponse.StatusCode!=HttpStatusCode.OK) 
            {
                return;
            }
            //using(StreamReader sr= new StreamReader(webResponse.GetResponseStream())) 
            //{
            //    Console.WriteLine(sr.ReadToEnd()); ;
            //}
            //
            using(FileStream fs=new FileStream("1.png", FileMode.Create))
            {
                webResponse.GetResponseStream().CopyTo(fs);
            }
            Console.ReadKey();
        }
    }
}